//
//  ChartingTableViewCell.m
//  intelligent
//
//  Created by 甘世清 on 2024/3/1.
//

#import "ChartingTableViewCell.h"
#import "ChartingTop1CollectionViewCell.h"
#import "ChartingTop2CollectionViewCell.h"
#import "ChartingTop3CollectionViewCell.h"
#import "ChartingTop4CollectionViewCell.h"
#import "LookImageView.h"
@implementation ChartingTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (void)SQ_Style:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
 
    self.contentView.backgroundColor = UIColor.clearColor;
  
    [self.contentView addSubview:self.collectionView];
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
}
- (void)setModel:(ChartingModel *)model{
    _model = model;
    [self.collectionView reloadData];
}

#pragma mark UICollectionViewDelegate,UICollectionViewDataSource
 
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.model.jsonArray.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView*)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath{
    
    [self.collectionView registerClass:NSClassFromString(self.model.identifier) forCellWithReuseIdentifier:self.model.identifier];
 
    BaseChartingCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:self.model.identifier forIndexPath:indexPath];
    cell.model = [self.model.jsonArray objectAtIndex:indexPath.item];
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
   
    return self.model.size;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
   
    return 12;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return 0;
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    return UIEdgeInsetsMake(0, 16, 0, 16);
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    HotModel * model =  [self.model.jsonArray objectAtIndex:indexPath.item];
    if ([self.model.identifier isEqualToString:@"ChartingTop2CollectionViewCell"]) {
        if (self.seletedBlock) {
            self.seletedBlock(model);
        }
    }
    for (HotModel * model1 in self.model.jsonArray) {
        model1.isSeleted = NO;
    }
    model.isSeleted = YES;
    [self.collectionView reloadData];
}
-(void)SQ_oneButton:(NSString*)url{
    LookImageView * view = [[LookImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDETH, SCREEN_HEIGHT)];
    [view.bgimage sd_setImageWithURL:SQURLImage(url)];
    LSTPopView * pop = [LSTPopView initWithCustomView:view
                                             parentView:nil
                                               popStyle:LSTPopStyleFade dismissStyle:LSTDismissStyleFade];
      pop.hemStyle = LSTHemStyleCenter;
    pop.dragStyle = LSTDragStyleAll;
    pop.dragDistance = SCREEN_WIDETH/3.f;
    [pop pop];
    LSTPopViewWK(pop)
       [view setImageBlock:^{
           [wk_pop dismiss];
       }];
      
      [pop setBgClickBlock:^{
          [wk_pop dismiss];
      }];
}
- (UICollectionView *)collectionView
{
    if (!_collectionView) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
        _collectionView.showsVerticalScrollIndicator = NO;
        _collectionView.showsHorizontalScrollIndicator = NO;
//        _collectionView.userInteractionEnabled = YES;
        _collectionView.backgroundColor = [UIColor clearColor];
//        _collectionView.alwaysBounceVertical = YES;
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
    }
    return _collectionView;
}

@end
